import BuffUtil from '@/BuffUtil';
import MathUtil from '@/MathUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 冰箭术
 **/
export default class FS_IceArrow extends AbilityBase {
    static instance: FS_IceArrow;
    buffType: AppBuffType = {
        id: 'buff_FS_IceArrow',
        art: this.art,
        name: this.abilityName,
        ubertip: '该单位受到了冰冷效果，攻击速度和移动速度降低了',
        stackCountMax: 10,
        dur: 10,
        targetArt: 'Abilities\\Spells\\Other\\FrostDamage\\FrostDamage.mdl',
        targetAttach: 'origin',
        attribute: {
            attackSpd_p: -0.05,
            move_speed: -5,
        },
    };
    constructor(id: string) {
        super(id);
        FS_IceArrow.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let ag = MathUtil.angleBetweenCoords(GetUnitX(source), GetUnitY(source), tarX, tarY);
        MovementCommon.LineMissile({
            missile: 'Abilities\\Weapons\\FrostWyrmMissile\\FrostWyrmMissile.mdl',
            caster: source,
            angle: ag,
            time: 1,
            distance: 800,
            onHit: this.onMissileHit.bind(this),
            radius: 60,
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    onMissileHit(p: LineMissileConfig, hit: unit) {
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 120 * lv + UnitCommon.取法强(p.caster) * (0.6 + lv * 0.6);
        DamageSystemInstance.applyIceDamage(hit, p.caster, dmg, this.id);
        // BuffUtil.addBuff(hit, this.buffType.id, p.caster);
        BuffCommon.addBuff({ target: hit, caster: p.caster, buffTypeId: this.buffType.id, ablityId: this.id });
    }
}
